package com.hebeu.gfh.controller;

import com.hebeu.gfh.pojo.po.College;
import com.hebeu.gfh.pojo.po.User;
import com.hebeu.gfh.service.collegeService;
import com.hebeu.gfh.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: 刘剑利
 * @Version: v1.0
 */
@RestController
@RequestMapping("/college")
public class collegeController {
    @Autowired
    collegeService collegeService;

    //查询所有学院
    @PostMapping("/findAllCollege")
    public R findAllCollege(){
        List<College> collegeList = collegeService.findAllCollege();
        return R.ok(collegeList);
    }
    //添加学院
    @PostMapping("/addCollege")
    public R addCollege(College college){
        try {
            collegeService.addCollege(college);
        }catch (Exception e){
            return R.error(500,"添加失败");
        }
            return R.ok();
    }
    //删除学院
    @PostMapping("/deleteCollege")
    public R deleteCollege(int collegeId){
        try {
            collegeService.deleteCollege(collegeId);
        }catch (Exception e){
            return R.error(500,"删除失败");
        }
        return R.ok();
    }
    //修改学院信息
    @PostMapping("/updateCollege")
    public R updateCollege(College college){
        try {
            collegeService.updateCollege(college);
        }catch (Exception e){
            return R.error(500,"修改失败");
        }
        return R.ok();
    }
    //根据id查询学院
    @PostMapping("/findCollegeById")
    public R findCollegeById(int collegeId){
        College college = collegeService.findCollegeById(collegeId);
        return R.ok(college);
    }
    //查询学院下所有学生
    @PostMapping("/CollegeMember")
    public R CollegeMember(int collegeId){
        List<User> userList = collegeService.CollegeMember(collegeId);
        return R.ok(userList);
    }
}
